import axios from "axios";
import Vue from "vue";
import { Notification } from "element-ui";
import store from "@/store";
import qs from "qs";

const service = axios.create({
  baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url
  withCredentials: true,
  timeout: 5000
});

// request interceptor
service.interceptors.request.use(
  config => {
    config.headers["Content-Type"] = "application/x-www-form-urlencoded";
    config.data = qs.stringify(config.data);
    return config;
  },
  error => {
    console.log(error); // for debug
    return Promise.reject(error);
  }
);

service.interceptors.response.use(response => {
  let res = response.data;
 
  return res;
});

export default service;
